// ClassWithRecursiveMethod.java
//
// Informatics 102 Spring 2012
// Code Example
//
// This class contains one public method, foo(), which takes an integer
// parameter and does one of three things:
//
// * If the parameter is 0, it prints "No more foos" and returns.
// * If the parameter is positive, it directly recurses, decrementing n
//   until it becomes zero.
// * If the parameter is negative, it makes a call to bar(), who calls
//   foo(), while incrementing n until it becomes zero.
//
// The method, then, demonstrates two kinds of recursion: direct recursion
// (where foo() calls foo()) and indirect recursion (where foo() calls
// another method that calls foo()).  This provides a useful test case
// for the DetectingFooRecursion aspect, which detects each kind of
// recursion separately.

public class ClassWithRecursiveMethod
{
	public void foo(int n)
	{
		if (n == 0)
		{
			System.out.println("No more foos");
		}
		else if (n < 0)
		{
			System.out.println("foo(" + n + ") calling bar()");
			bar(n + 1);
		}
		else
		{
			System.out.println("foo(" + n + ")");
			foo(n - 1);
		}
	}
	
	
	private void bar(int n)
	{
		System.out.println("bar(" + n + ")");
		foo(n);
	}
}
